<?php 
namespace App\Models;

use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Eloquent\Model;

class ModelX extends Model{

    public $rules =  [

    ];

    public function validator(){
        $validator = Validator::make( $this->attributes,$this->rules);
        $b = false;
        if ($validator->fails()) {
            $b = $validator->messages()->all();
        }
        return $b;
    }

    public function saveX(){
        $result = ['errorCode'=>0,"message"=>[]];
        $validator = $this->validator();
        if($validator){
            $result['errorCode'] = 600001;
            $result['message'] = $validator;
        }else{
            try{
                $this->save();
            }catch(\Exception $e){
                $result['errorCode'] = 600002;
                $result['message'] = [$e->getMessage()];
            }
        }
        return $result;
    }
}